# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html

import json
class ItcastPipeline(object):
    # 开启写入
    def open_spider(self, spider):
        self.file = open('01.json', 'w')

    def process_item(self, item, spider):
        print('*' * 50)
        print(spider.name)
        dict_data = dict(item)
        str_data = json.dumps(dict_data) + '\n'
        self.file.write(str_data)
        return item

    # 关闭写入
    def close_spider(self, spider):
        self.file.close()


